package com.beetlestech.nfe.main.biz.com.impl;

import java.util.ArrayList;
import java.util.List;

import com.beetlestech.nfe.fw.core.biz.AbstractDBLogic;
import com.beetlestech.nfe.fw.core.util.CollectionUtil;
import com.beetlestech.nfe.main.biz.com.HbExaminationfile;
import com.beetlestech.nfe.main.biz.com.dto.VexaminationfileInfoDTO;
import com.beetlestech.nfe.main.biz.com.dto.VexaminationfilecountInfoDTO;
import com.beetlestech.nfe.main.biz.constant.CommonConstant;
import com.beetlestech.nfe.main.biz.constant.CtgCodeConstant;
import com.beetlestech.nfe.main.biz.constant.HbMessageCode;
import com.beetlestech.nfe.main.db.constant.SQLConstant;
import com.beetlestech.nfe.main.db.view.VexaminationfileDTO;
import com.beetlestech.nfe.main.db.view.VexaminationfilecountDTO;
import com.beetlestech.nfe.main.db.view.support.VexaminationfileDTOSupport;
import com.beetlestech.nfe.main.db.view.support.VexaminationfilecountDTOSupport;

public class HbExaminationfileImpl extends AbstractDBLogic implements HbExaminationfile, CtgCodeConstant, HbMessageCode, CommonConstant, SQLConstant {

	@Override
	public VexaminationfileInfoDTO[] getExaminationfile(Integer type) {
		
		VexaminationfileDTO searchDTO = new VexaminationfileDTO();
		searchDTO.settype(type);
		
		List<VexaminationfileDTO> searchList = queryDAO.queryForObjectList(VexaminationfileDTOSupport.EQUAL_SEARCH, searchDTO);
		
		List<VexaminationfileInfoDTO> examinationfileInfoDTOList = new ArrayList<VexaminationfileInfoDTO>();
		if (CollectionUtil.isEmpty(searchList)) {
			//0件場合
			createApplicationException(M10090WS);
		} else {
			for (VexaminationfileDTO item : searchList) {
				examinationfileInfoDTOList.add(setexaminationfileInfo(item));
			}
		}

		return examinationfileInfoDTOList.toArray(new VexaminationfileInfoDTO[examinationfileInfoDTOList.size()]);
	}
	
	@Override
	public VexaminationfilecountInfoDTO[] getExaminationfileCount() {
		
		VexaminationfilecountDTO searchDTO = new VexaminationfilecountDTO();
		
		List<VexaminationfilecountDTO> searchList = queryDAO.queryForObjectList(VexaminationfilecountDTOSupport.SQL_SEARCH, searchDTO);
		
		List<VexaminationfilecountInfoDTO> resultList = new ArrayList<VexaminationfilecountInfoDTO>();
		if (CollectionUtil.isEmpty(searchList)) {
			//0件場合
			createApplicationException(M10090WS);
		} else {
			for (VexaminationfilecountDTO item : searchList) {
				resultList.add(setexaminationfilecountInfo(item));
			}
		}

		return resultList.toArray(new VexaminationfilecountInfoDTO[resultList.size()]);
	}

	private VexaminationfileInfoDTO setexaminationfileInfo(VexaminationfileDTO targetDto){
		
		VexaminationfileInfoDTO convertDTO = new VexaminationfileInfoDTO();
		convertDTO.setexaminationdocid(targetDto.getexaminationdocid());
		convertDTO.setname(targetDto.getname());
		convertDTO.setfileid(targetDto.getfileid());
		convertDTO.setpath(targetDto.getpath());
		convertDTO.settype(targetDto.gettype());
		
		return convertDTO;
	}

	private VexaminationfilecountInfoDTO setexaminationfilecountInfo(VexaminationfilecountDTO targetDto){
		
		VexaminationfilecountInfoDTO convertDTO = new VexaminationfilecountInfoDTO();
		convertDTO.settype(targetDto.gettype());
		convertDTO.setcatagorycname(targetDto.getcatagorycname());
		convertDTO.setfileCount(targetDto.getfileCount());
		
		return convertDTO;
	}
}
